package com.example.studymvvmproject01.http.intercept

import com.example.studymvvmproject01.utils.MyConfig
import com.example.studymvvmproject01.utils.SpUtil
import okhttp3.Interceptor
import okhttp3.Request
import okhttp3.Response

/**
 * cookie拦截器
 * 将cookie添加到请求头上
 */
class AddCookiesInterceptor:Interceptor {
    override fun intercept(chain: Interceptor.Chain): Response {
        val builder:Request.Builder=chain.request().newBuilder();
        val stringSet = SpUtil.getString(MyConfig.COOKIE)
//        for(cookie in stringSet){
            builder.addHeader("Authorization","Bearer "+stringSet)
//        }
        return chain.proceed(builder.build())

    }

}